﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StockCommon.formula
{
    public class StockPriceFormula
    {
        public enum SecuritiesType
        {
            上市股票 = 1,
            櫃檯股票 = 2,
            認購售權證 = 3,
            轉換公司債 = 4,
            受益證券 = 5,
            公司債 = 6
        }
        public static void get股票UpDownStep(double v, out double up, out double down)
        {
            double obup1 = v * 1.07;
            double obdw1 = v * 0.93;
            double step = 0;
            up = 0;
            down = 0;

            if (obup1 <= 10)
            {
                step = 0.01;
            }
            else
                if ((obup1 > 10) && (obup1 <= 50))
                {
                    step = 0.05;
                }
                else
                    if ((obup1 > 50) && (obup1 <= 100))
                    {
                        step = 0.1;
                    }
                    else
                        if ((obup1 > 100) && (obup1 <= 500))
                        {
                            step = 0.5;
                        }
                        else
                            if ((obup1 > 500) && (obup1 <= 1000))
                            {
                                step = 1;
                            }
                            else
                            {
                                step = 5;
                            }
            up = ((Math.Floor(((Math.Floor(obup1 / step) * step) * 100) * 100)) / 100) / 100;

            //-------------跌
            if (obdw1 <= 10)
            {
                step = 0.01;
            }
            else
                if ((obdw1 > 10) && (obdw1 <= 50))
                {
                    step = 0.05;
                }
                else
                    if ((obdw1 > 50) && (obdw1 <= 100))
                    {
                        step = 0.1;
                    }
                    else
                        if ((obdw1 > 100) && (obdw1 <= 500))
                        {
                            step = 0.5;
                        }
                        else
                            if ((obdw1 > 500) && (obdw1 <= 1000))
                            {
                                step = 1;
                            }
                            else
                            {
                                step = 5;
                            }
            down = ((Math.Floor(((Math.Ceiling(obdw1 / step) * step) * 100) * 100)) / 100) / 100;



        }
        public static void getUpDownStep(SecuritiesType t, double v, out double up, out double down)
        {
       //     if (t.Equals(SecuritiesType.上市股票))
         //   {
                get股票UpDownStep(v, out up, out down);
          //  }
            //價格乃是以前一天為準的
            //必須要看漲停根跌停落在哪一個區間內.而使用該區間的公式.. 至於價格step則是
            //所以有可能漲停 與跌停 所使用的 區間不同,而使用的step不同
        }
    }
}
